Repository navigation
feat(billing): add opt-in Stripe top-ups credited only from verified webhooks - #75
Conversation
…webhooks PAYMENTS_ENABLED (off by default) adds POST /v1/payments/checkout, which creates a Stripe Checkout Session for a whole-cent USD amount between $0.50 and $1,000 from an allowlisted return origin, with per-principal daily limits and idempotent replay. POST /v1/payments/webhook verifies the raw body's v1 signature and timestamp, claims each event before any callback, and checks livemode, merchant, currency, amount and session against the stored checkout. Credits are added only through the injected payment callback, once per checkout; refunds and disputes append compensation. The browser return page never credits. Configuration holds secret references only (migration 0038).
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
multillm-proxy | cc933b4 | Oct 09 2026, 08:00 AM |
Summary
Adds opt-in Stripe top-ups. Credits are added only from a verified Stripe webhook, never from the browser's return page. With
PAYMENTS_ENABLEDunset oroff(the default),/v1/payments/*returns 404 without touching payment storage, and nothing else changes.PAYMENTS_ENABLED. Empty means off; a malformed value is off with one warning.PAYMENT_PROCESSOR_CONFIG_JSONholds{"processor": "stripe", "secret_key_ref", "return_origins", "product_name"}.PAYMENT_WEBHOOK_KEY_REFnames the webhook signing secret.POST /v1/payments/checkout(gateway key) takes{amount_microusd, currency: "USD", idempotency_key, return_url}.payment_velocity_limited).Idempotency-Keyand only an opaque checkout ID in metadata, then checks the returned session's amount, currency and URL origin.POST /v1/payments/webhooktakes no gateway key and is exempt from CSRF.Stripe-Signature:v1values only, HMAC-SHA256 compared in constant time, timestamp within ±300 s.checkout.session.completedwithpayment_status: paid, orcheckout.session.async_payment_succeeded, credits once per checkout.checkout.session.async_payment_failedmarks the checkout failed.charge.refundedandcharge.dispute.createdappend compensation.PaymentCallback. When it is unavailable, the event stayspending_creditand the webhook returns 503 so Stripe retries.Details are in
docs/payment-billing.md. Tests use fake HTTP only; nothing calls Stripe.Wiring
All new files; no existing file changes. The existing Worker forwards the webhook to the Container byte for byte, without an edge key check, which a test confirms. The Wave 7 integration adds:
register_payment_routeswith the D1 store, the tenant context and the credits ledger's callback;paymentsendpoint and its dispatcher entry.Taxes, invoices and the processor account itself remain operator decisions.
Shared registrations
tests/test_payment_billing_worker.mjsintest:worker.worker/payment-webhooks.mjsin the edge module inventory, and both payment routes in the Flask route inventory.PAYMENTS_ENABLED,PAYMENT_PROCESSOR_CONFIG_JSONandPAYMENT_WEBHOOK_KEY_REFin the Container env keys.payment_checkouts,payment_events,payment_velocityandpayment_auditinREQUIRED_D1_TABLES.Stacked on #74
Migration numbers must be contiguous in each PR, so this branch merges
feat/credits-ledger(#74, migration 0037), which stacks on #73, #72, #71 and #70. Merge those first.Tests
tests/test_payment_billing.pyandtests/test_payment_billing_worker.mjscover:npm run test:worker: 1,850 passed.npm run test:integration: 7 passed.cf:migrations:checkreports 38 contiguous, additive migrations.test:deploy, free routes, client headers and thewrangler deploy --dry-runbundle all pass.tests/test_frontend_build.mjsfails locally because@tailwindcss/cliis not installed. It fails the same way on main.Apply the migration before enabling the flag:
npx wrangler d1 migrations apply multillm-intelligence --remote.CI notes
python/nodejobs: the dependency-audit steps fail on every branch, including main. fix(deps): clear the CI dependency audit advisories #42 fixes that.AdmissionCoordinatorDurable Object migration, whichwrangler versions uploadcannot apply. This is expected untilwrangler deployruns on main.This is part of Wave 7. The README line comes with the Wave 7 integration PR.